package red;

import java.io.IOException;
import java.net.UnknownHostException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class SSLClient {

	private SSLSocket sslSocket;

	public SSLClient(String hostname, int port, int timeOut) throws IOException {
		if (port > 0) {
			SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory
					.getDefault();

			sslSocket = (SSLSocket) sslsocketfactory.createSocket(hostname,
					port);
			sslSocket.setSoTimeout(timeOut);
		}
	}

	public void sendData(OutputJob outJob) {
		try {
			outJob.setOutputStream(sslSocket.getOutputStream());
			outJob.run();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void processRecievedData(InputJob inJob) {
		try {
			inJob.setInputStream(sslSocket.getInputStream());
			inJob.run();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void stop() {
		try {
			sslSocket.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}